package shoot;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;
import javax.swing.Timer;

public class Board extends JPanel implements ActionListener {

	private Personnage perso;
	private Timer timer;

	public Board() {
		super();
		setPreferredSize(new Dimension(800, 600));
		addKeyListener(new TAdapter());
		setBackground(Color.BLACK);
		setDoubleBuffered(true);
		setFocusable(true);
		this.perso = new Personnage("trunks.png", 400, 300);
		timer = new Timer(300, this);
		timer.start();
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
		g2d.drawImage(perso.getImage(), perso.getDx(), perso.getDy(), this);
		g.dispose();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		repaint();
	}

	class TAdapter extends KeyAdapter {		
		public void keyPressed(KeyEvent e) {
			perso.keyPressed(e);			
		}
	}
}
